package ru.ifmo.common.util;

import java.util.List;

/**
 * @author Roman Kolganov
 *         02.12.11
 */
public class MathUtil {

    public static long greatestCommonDivisor(long a, long b) {
        while (b != 0) {
            long t = a;
            a = b;
            b = t % b;
        }
        return a;
    }

    public static long lowestCommonMultiple(long a, long b) {
        return a * b / greatestCommonDivisor(a, b);
    }

    public static long lowestCommonMultiple(List<Integer> args) {
        long result = 1;
        for (long current : args) {
            result = lowestCommonMultiple(result, current);
        }
        return result;
    }

}
